package com.zian.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

@Getter
public enum GenderEnum {

    MALE(1,"男"),
    FEMALE(2,"女");

    GenderEnum(int code, String name){
        this.code = code;
        this.name = name;
    }
    @JsonValue // 枚举序列化时返回此字段
    @EnumValue  // 枚举序列化时返回此字段
    private final int code;
    private final String name;

    public static String getNameByCode(int code){
        for(GenderEnum genderEnum : GenderEnum.values()){
            if(genderEnum.getCode() == code){
                return genderEnum.getName();
            }
        }
        return null;
    }
    public static GenderEnum getByCode(int code){
        for(GenderEnum genderEnum : GenderEnum.values()){
            if(genderEnum.getCode() == code){
                return genderEnum;
            }
        }
        return null;
    }
}

